﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SnippetDoc.Entities;
using SnippetDoc.Utils;

namespace SnippetDoc.UnitTests.Utils
{
    /// <summary>
    /// Summary description for FolderScannerTest
    /// </summary>
    [TestClass]
    public class FolderScannerTest
    {
        [TestMethod]
        public void TestScanSnippetDirectory_ValidDirectoryWith1Item_ShouldReturnOneItem()
        {
            //Arrange


            //Act
            IEnumerable<SnippetFolder> snippetFolders = new FolderScanner().ScanSnippetDirectory("OneSnippetFolder");

            //Assert
            Assert.AreEqual(1, snippetFolders.Count(), "There should be 1 snippet folder");
            Assert.AreEqual("OneSnippetFolder", snippetFolders.ElementAt(0).Name, "The name of the folder should match");
        }

        [TestMethod]
        [ExpectedException(typeof(FileNotFoundException))]
        public void TestScanSnippetDirectory_InvalidDirectory_ShouldThrowException()
        {
            //Act
            new FolderScanner().ScanSnippetDirectory("abcdefg");
        }

        [TestMethod]
        public void TestScanSnippetDirectory_ValidDirectoryWith1SnippetAnd1OtherFile_ShouldJustFind1Snippet()
        {
            //Act
            IEnumerable<SnippetFolder> snippetFolders = new FolderScanner().ScanSnippetDirectory("SnippetFolderWithOtherFiles");

            //Assert
            Assert.AreEqual(1, snippetFolders.Count(), "There should be 1 snippet folder");
            Assert.AreEqual("SnippetFolderWithOtherFiles", snippetFolders.ElementAt(0).Name, "The name of the folder should match");
            Assert.AreEqual(1, snippetFolders.ElementAt(0).Snippets.Count(), "There should be just 1 snippet found");
        }

        [TestMethod]
        public void TestScanSnippetDirectory_NestedSubfolders_ShouldReturn2Snippets()
        {
            //Act
            IEnumerable<SnippetFolder> snippetFolders = new FolderScanner().ScanSnippetDirectory("NestedFolders");

            //Assert
            Assert.AreEqual(2, snippetFolders.Count(), "There should be 2 folders");

            Assert.IsTrue(snippetFolders.FirstOrDefault(x => x.Name == "Java") != null, "your comment");
            Assert.IsTrue(snippetFolders.FirstOrDefault(x => x.Name == "NestedFolders") != null, "your comment");
        }
    }
}
